package com.example.consult.service;

import com.example.consult.mapper.UserMapper;
import com.example.consult.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public UserInfo doLogin(String userAccount,String userPwd){
        return userMapper.searchByUserAccountAndPassword(userAccount,userPwd);
    }

    public boolean isUsed(String userAccount){
        return userMapper.searchByUserAccount(userAccount) == 0;
    }

    public UserInfo register(String userAccount,String userPwd){
        UserInfo userInfo  = new UserInfo();
        userInfo.setUser_account(userAccount);
        userInfo.setUser_pwd(userPwd);
        userInfo.setUser_name(userAccount);
        userMapper.insertUser(userInfo);
        return userInfo;
    }

    public List<UserInfo> getAll(){
        return userMapper.getAll();
    }

}
